import {
  getMerchantInfo,
  getHomeInit
} from '../../utils/networkRequest.js'
import Net from '../../utils/network.js'
Page({
  data: {
    dataInfo: null,
  },
  onShow: function(options) {
    let self = this;
    let value = wx.getStorageSync('token') //从本地缓存中获取Session信息

    if (value) {
      getMerchantInfo((r) => {
        console.log(r)
        if (r.code == 0) {
          let isShowJieChe=false;
          r.data.permissions.map((o, i) => {
            if (o.permission_name == "auto_manager") {
              isShowJieChe=true;
              return;
            }
          }) 
          self.setData({
            dataInfo: r.data,
            isShowJieChe: isShowJieChe
          })
        } else {
          wx.showToast({
            icon: "none",
            title: r.message,
          })
        }


      })
    } else {

      setTimeout(() => {
        getMerchantInfo((r) => {
          if (r.code == 0) {
            let isShowJieChe = false;
            r.data.permissions.map((o, i) => {
              if (o.permission_name == "auto_manager") {
                isShowJieChe = true;
                return;
              }
            })

            self.setData({
              dataInfo: r.data,
              isShowJieChe: isShowJieChe
            })
          } else {
            wx.showToast({
              icon: "none",
              title: r.message,
            })
          }

        })
      }, 3000)

    }
  },
  openAppJieChe: function() {
    wx.navigateToMiniProgram({
      appId: 'wx0da2defc20ec24b3',
      path: 'pages/jieche/jieche',
      extraData: {
        foo: 'bar'
      },
      envVersion: 'develop',
      success(res) {
        // 打开成功
      },
      fail(e) {}
    })
  },
  //前往页面
  goRouter: function(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: item.route,
    })
  },
  //跳转到搜索
  goSearch: function() {
    wx.navigateTo({
      url: '../carmanagebox/carsearch/carsearch'
    })
  },
  //下啦刷新
  onPullDownRefresh: function () {
    let self = this; 
    getMerchantInfo((r) => {
      if (r.code == 0) {
        let isShowJieChe = false;
        r.data.permissions.map((o, i) => {
          if (o.permission_name == "auto_manager") {
            isShowJieChe = true;
            return;
          }
        })

        self.setData({
          dataInfo: r.data,
          isShowJieChe: isShowJieChe
        })
        wx.stopPullDownRefresh()
      } else {
        wx.showToast({
          icon: "none",
          title: r.message,
        })
        wx.stopPullDownRefresh()
      }

    })
   
  },
})